﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using YArchitech.LIB;

namespace YArchitech.Plumbing
{
	public partial class FormLevels : System.Windows.Forms.Form
	{
		public FormLevels()
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			base.Icon = Resource.YArchitechIcon;
		}

		public FormLevels(List<Element> allLevels)
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			base.Icon = Resource.YArchitechIcon;
			this.InitList(allLevels);
			base.ShowDialog();
		}

		private void InitList(List<Element> levels)
		{
			foreach (Element element in levels)
			{
				this.listLevels.Items.Add(new ListItem(element.Name, element.ToString(), element));
			}
			this.listLevels.SelectedIndex = 0;
		}

		private void listLevels_SelectedIndexChanged(object sender, EventArgs e)
		{
			ListItem listItem = this.listLevels.SelectedItem as ListItem;
			this.desLevel = (listItem.Tag as Element);
		}

		private void btnChoose_Click(object sender, EventArgs e)
		{
			base.Close();
			base.DialogResult = DialogResult.Retry;
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			base.Close();
			base.DialogResult = DialogResult.OK;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.Close();
			base.DialogResult = DialogResult.Cancel;
		}

		private void listLevels_MouseDoubleClick(object sender, MouseEventArgs e)
		{
			if (this.listLevels.SelectedItem == null)
			{
				return;
			}
			ListItem listItem = this.listLevels.SelectedItem as ListItem;
			this.desLevel = (listItem.Tag as Element);
			this.btnOk_Click(null, null);
		}

		public List<Element> selectedElements;

		public Element desLevel;
	}
}
